package com.xiaoyilin.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Fanout Exchange
 * 发布订阅模式(Fanout)：转发消息到所有绑定队列，忽略routing_key。
 */
@Configuration
public class RabbitFanoutConfig {

    @Bean(name = "aMyFanoutQueue")
    public Queue aMyFanoutQueue() {
        return new Queue("my.fanout.queue.a");
    }

    @Bean(name = "bMyFanoutQueue")
    public Queue bMyFanoutQueue() {
        return new Queue("my.fanout.queue.b");
    }

    @Bean(name = "cMyFanoutQueue")
    public Queue cMyFanoutQueue() {
        return new Queue("my.fanout.queue.c");
    }

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("my.fanout.exchange");
    }

    @Bean
    public Binding bindingExchangeA(@Qualifier("aMyFanoutQueue") Queue aMyFanoutQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(aMyFanoutQueue).to(fanoutExchange);
    }

    @Bean
    public Binding bindingExchangeB(@Qualifier("bMyFanoutQueue") Queue bMyFanoutQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(bMyFanoutQueue).to(fanoutExchange);
    }

    @Bean
    public Binding bindingExchangeC(@Qualifier("cMyFanoutQueue") Queue cMyFanoutQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(cMyFanoutQueue).to(fanoutExchange);
    }


}
